package com.ruoyi.mall.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mall.domain.ProductSpecValues;
import com.ruoyi.mall.service.IProductSpecValuesService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品规格值Controller
 * 
 * @author ruoyi
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/mall/values")
public class ProductSpecValuesController extends BaseController
{
    @Autowired
    private IProductSpecValuesService productSpecValuesService;

    /**
     * 查询商品规格值列表
     */
    @PreAuthorize("@ss.hasPermi('mall:values:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductSpecValues productSpecValues)
    {
        startPage();
        List<ProductSpecValues> list = productSpecValuesService.selectProductSpecValuesList(productSpecValues);
        return getDataTable(list);
    }

    /**
     * 导出商品规格值列表
     */
    @PreAuthorize("@ss.hasPermi('mall:values:export')")
    @Log(title = "商品规格值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductSpecValues productSpecValues)
    {
        List<ProductSpecValues> list = productSpecValuesService.selectProductSpecValuesList(productSpecValues);
        ExcelUtil<ProductSpecValues> util = new ExcelUtil<ProductSpecValues>(ProductSpecValues.class);
        util.exportExcel(response, list, "商品规格值数据");
    }

    /**
     * 获取商品规格值详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:values:query')")
    @GetMapping(value = "/{specValueId}")
    public AjaxResult getInfo(@PathVariable("specValueId") Long specValueId)
    {
        return success(productSpecValuesService.selectProductSpecValuesBySpecValueId(specValueId));
    }

    /**
     * 新增商品规格值
     */
    @PreAuthorize("@ss.hasPermi('mall:values:add')")
    @Log(title = "商品规格值", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductSpecValues productSpecValues)
    {
        return toAjax(productSpecValuesService.insertProductSpecValues(productSpecValues));
    }

    /**
     * 修改商品规格值
     */
    @PreAuthorize("@ss.hasPermi('mall:values:edit')")
    @Log(title = "商品规格值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductSpecValues productSpecValues)
    {
        return toAjax(productSpecValuesService.updateProductSpecValues(productSpecValues));
    }

    /**
     * 删除商品规格值
     */
    @PreAuthorize("@ss.hasPermi('mall:values:remove')")
    @Log(title = "商品规格值", businessType = BusinessType.DELETE)
	@DeleteMapping("/{specValueIds}")
    public AjaxResult remove(@PathVariable Long[] specValueIds)
    {
        return toAjax(productSpecValuesService.deleteProductSpecValuesBySpecValueIds(specValueIds));
    }
}
